﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// CreateMajorSetupWindow.xaml 的交互逻辑
        /// </summary>
        public partial class CreateMajorSetupWindow
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public CreateMajorSetupWindow()
                {
                        InitializeComponent();
                }

                private void Window_Loaded(object sender, RoutedEventArgs e)
                {
                        LayoutRoot.DataContext = _gm;
                }

                private void Window_OnMouseDown(object sender, MouseButtonEventArgs e)
                {
                        if (e.ChangedButton == MouseButton.Left)
                        {
                                DragMove();
                        }
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        if (_gm.Major == null)
                        {
                                MessageBox.Show("专业不能为空");
                                return;
                        }

                        try
                        {
                                MajorSetup majorSetup =
                                        _gm.Department.CreateMajorSetup(_gm.Major.Id, _gm.MajorSetupManagerName,_gm.MajorSetupTeachingManagerName);
                                majorSetup.Insert();

                                _gm.MajorSetups.Add(majorSetup);
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        Close();
                }

                
        }
}